package com.hspedu.com.jdbc.practice;

import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Properties;
import java.util.Scanner;

/**
 * @author DL5O
 * @version 1.0
 * 删除记录
 */
public class Practice03 {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Properties properties = new Properties();
        properties.load(new FileReader("src\\jdbc.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String url = properties.getProperty("url");
        String driver = properties.getProperty("driver");

        //1.注册驱动
        Class.forName(driver);
        //2.得到连接
        Connection connection = DriverManager.getConnection(url, user, password);//进行注册
        System.out.print("请输入要删除管理员的名字:");
        String admin_name = sc.nextLine();


        String sql = "delete from admin where name = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, admin_name);
        int rows = preparedStatement.executeUpdate();
        if (rows > 0) {
            System.out.println("执行成功");
        }else{
            System.out.println("执行失败");
        }

        preparedStatement.close();
        connection.close();
    }
}
